package com.zk.springboot;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent;
import org.springframework.boot.context.event.ApplicationPreparedEvent;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.ApplicationListener;

import com.zk.springboot.starter.ApplicationFrame;

@SpringBootApplication
public class MainApplication {

	public static void main(String[] args) {
		SpringApplication app = new SpringApplication(MainApplication.class);
		app.addListeners(new ApplicationPrepareListener(), new ApplicationReadyListener(),
				new ApplicationEnvPrepareListener());
		app.run(args);
	}
}

/*
 * 用于加载资源，包括第三方jar包
 */
class ApplicationPrepareListener implements ApplicationListener<ApplicationPreparedEvent> {

	@Override
	public void onApplicationEvent(ApplicationPreparedEvent event) {
		// TODO Auto-generated method stub
	}

}

/*
 * bean已经加载到容器中，用于加载模块
 */
class ApplicationReadyListener implements ApplicationListener<ApplicationReadyEvent> {

	@Override
	public void onApplicationEvent(ApplicationReadyEvent event) {
		// TODO Auto-generated method stub
		// 将所有service加入服务管理器,方便模块之间相互调用,此时bean已经注入完成
		ApplicationFrame.getFrame().init(event.getApplicationContext());
	}

}

/*
 * 用于加载静态资源什么的
 */
class ApplicationEnvPrepareListener implements ApplicationListener<ApplicationEnvironmentPreparedEvent> {

	@Override
	public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) {
		// TODO Auto-generated method stub
	}

}